<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>BadgerDB: bufmgr/src/buffer.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">BadgerDB
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">bufmgr/src/buffer.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#pragma once</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;file.h&quot;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;bufHashTbl.h&quot;</span>
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="keyword">namespace </span>badgerdb {
<a name="l00014"></a>00014 
<a name="l00018"></a>00018 <span class="keyword">class </span>BufMgr;
<a name="l00019"></a>00019 
<a name="l00023"></a><a class="code" href="classbadgerdb_1_1_buf_desc.html">00023</a> <span class="keyword">class </span><a class="code" href="classbadgerdb_1_1_buf_desc.html" title="Class for maintaining information about buffer pool frames.">BufDesc</a> {
<a name="l00024"></a>00024 
<a name="l00025"></a>00025   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classbadgerdb_1_1_buf_mgr.html" title="The central class which manages the buffer pool including frame allocation and deallocation to pages ...">BufMgr</a>;
<a name="l00026"></a>00026 
<a name="l00027"></a>00027  <span class="keyword">private</span>:
<a name="l00031"></a>00031   <a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file;
<a name="l00032"></a>00032 
<a name="l00036"></a>00036   <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> pageNo;
<a name="l00037"></a>00037 
<a name="l00041"></a>00041   <a class="code" href="namespacebadgerdb.html#a1e7378fbefaea050a47e6cde929e9c01" title="Identifier for a frame in buffer pool.">FrameId</a> frameNo;
<a name="l00042"></a>00042 
<a name="l00046"></a>00046   <span class="keywordtype">int</span> pinCnt;
<a name="l00047"></a>00047 
<a name="l00051"></a>00051   <span class="keywordtype">bool</span> dirty;
<a name="l00052"></a>00052 
<a name="l00056"></a>00056   <span class="keywordtype">bool</span> valid;
<a name="l00057"></a>00057 
<a name="l00061"></a>00061   <span class="keywordtype">bool</span> refbit;
<a name="l00062"></a>00062 
<a name="l00066"></a>00066   <span class="keywordtype">void</span> Clear()
<a name="l00067"></a>00067   {
<a name="l00068"></a>00068     pinCnt = 0;
<a name="l00069"></a>00069     file = NULL;
<a name="l00070"></a>00070     pageNo = <a class="code" href="classbadgerdb_1_1_page.html#a785a1e756d47fb7f8f3603a3fe8ffcef">Page::INVALID_NUMBER</a>;
<a name="l00071"></a>00071     dirty = <span class="keyword">false</span>;
<a name="l00072"></a>00072     refbit = <span class="keyword">false</span>;
<a name="l00073"></a>00073     valid = <span class="keyword">false</span>;
<a name="l00074"></a>00074   };
<a name="l00075"></a>00075 
<a name="l00083"></a>00083   <span class="keywordtype">void</span> Set(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* filePtr, <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> pageNum)
<a name="l00084"></a>00084   { 
<a name="l00085"></a>00085     file = filePtr;
<a name="l00086"></a>00086     pageNo = pageNum;
<a name="l00087"></a>00087     pinCnt = 1;
<a name="l00088"></a>00088     dirty = <span class="keyword">false</span>;
<a name="l00089"></a>00089     valid = <span class="keyword">true</span>;
<a name="l00090"></a>00090     refbit = <span class="keyword">true</span>;
<a name="l00091"></a>00091   }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093   <span class="keywordtype">void</span> Print()
<a name="l00094"></a>00094   {
<a name="l00095"></a>00095     <span class="keywordflow">if</span>(file)
<a name="l00096"></a>00096     {
<a name="l00097"></a>00097       std::cout &lt;&lt; <span class="stringliteral">&quot;file:&quot;</span> &lt;&lt; file-&gt;<a class="code" href="classbadgerdb_1_1_file.html#ac61ce3c2233fd1f7e2e2a8a5a7640936">filename</a>() &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00098"></a>00098       std::cout &lt;&lt; <span class="stringliteral">&quot;pageNo:&quot;</span> &lt;&lt; pageNo &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00099"></a>00099     }
<a name="l00100"></a>00100     <span class="keywordflow">else</span>
<a name="l00101"></a>00101       std::cout &lt;&lt; <span class="stringliteral">&quot;file:NULL &quot;</span>;
<a name="l00102"></a>00102 
<a name="l00103"></a>00103     std::cout &lt;&lt; <span class="stringliteral">&quot;valid:&quot;</span> &lt;&lt; valid &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00104"></a>00104     std::cout &lt;&lt; <span class="stringliteral">&quot;pinCnt:&quot;</span> &lt;&lt; pinCnt &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00105"></a>00105     std::cout &lt;&lt; <span class="stringliteral">&quot;dirty:&quot;</span> &lt;&lt; dirty &lt;&lt; <span class="stringliteral">&quot; &quot;</span>;
<a name="l00106"></a>00106     std::cout &lt;&lt; <span class="stringliteral">&quot;refbit:&quot;</span> &lt;&lt; refbit &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span>;
<a name="l00107"></a>00107   }
<a name="l00108"></a>00108 
<a name="l00112"></a>00112   <a class="code" href="classbadgerdb_1_1_buf_desc.html" title="Class for maintaining information about buffer pool frames.">BufDesc</a>()
<a name="l00113"></a>00113   {
<a name="l00114"></a>00114     Clear();
<a name="l00115"></a>00115   }
<a name="l00116"></a>00116 };
<a name="l00117"></a>00117 
<a name="l00118"></a>00118 
<a name="l00122"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html">00122</a> <span class="keyword">struct </span><a class="code" href="structbadgerdb_1_1_buf_stats.html" title="Class to maintain statistics of buffer usage.">BufStats</a>
<a name="l00123"></a>00123 {
<a name="l00127"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html#a3e7eb386ac728ed028bd2a8bb7960827">00127</a>   <span class="keywordtype">int</span> <a class="code" href="structbadgerdb_1_1_buf_stats.html#a3e7eb386ac728ed028bd2a8bb7960827">accesses</a>;
<a name="l00128"></a>00128 
<a name="l00132"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html#a60cde025ce745b6bc41a0ba27daf04e0">00132</a>   <span class="keywordtype">int</span> <a class="code" href="structbadgerdb_1_1_buf_stats.html#a60cde025ce745b6bc41a0ba27daf04e0">diskreads</a>;
<a name="l00133"></a>00133 
<a name="l00137"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html#a4bd2081fdaddaa309b401575eeb6a86e">00137</a>   <span class="keywordtype">int</span> <a class="code" href="structbadgerdb_1_1_buf_stats.html#a4bd2081fdaddaa309b401575eeb6a86e">diskwrites</a>;
<a name="l00138"></a>00138 
<a name="l00142"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html#a04a848e5458491fd3ea56133464cadbd">00142</a>   <span class="keywordtype">void</span> <a class="code" href="structbadgerdb_1_1_buf_stats.html#a04a848e5458491fd3ea56133464cadbd">clear</a>()
<a name="l00143"></a>00143   {
<a name="l00144"></a>00144     <a class="code" href="structbadgerdb_1_1_buf_stats.html#a3e7eb386ac728ed028bd2a8bb7960827">accesses</a> = <a class="code" href="structbadgerdb_1_1_buf_stats.html#a60cde025ce745b6bc41a0ba27daf04e0">diskreads</a> = <a class="code" href="structbadgerdb_1_1_buf_stats.html#a4bd2081fdaddaa309b401575eeb6a86e">diskwrites</a> = 0;
<a name="l00145"></a>00145   }
<a name="l00146"></a>00146       
<a name="l00150"></a><a class="code" href="structbadgerdb_1_1_buf_stats.html#ad9848260b3b787f15eb1b960b0f8e769">00150</a>   <a class="code" href="structbadgerdb_1_1_buf_stats.html#ad9848260b3b787f15eb1b960b0f8e769">BufStats</a>()
<a name="l00151"></a>00151   {
<a name="l00152"></a>00152     <a class="code" href="structbadgerdb_1_1_buf_stats.html#a04a848e5458491fd3ea56133464cadbd">clear</a>();
<a name="l00153"></a>00153   }
<a name="l00154"></a>00154 };
<a name="l00155"></a>00155 
<a name="l00156"></a>00156 
<a name="l00160"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html">00160</a> <span class="keyword">class </span><a class="code" href="classbadgerdb_1_1_buf_mgr.html" title="The central class which manages the buffer pool including frame allocation and deallocation to pages ...">BufMgr</a> 
<a name="l00161"></a>00161 {
<a name="l00162"></a>00162  <span class="keyword">private</span>:
<a name="l00166"></a>00166   <a class="code" href="namespacebadgerdb.html#a1e7378fbefaea050a47e6cde929e9c01" title="Identifier for a frame in buffer pool.">FrameId</a> clockHand;
<a name="l00167"></a>00167 
<a name="l00171"></a>00171   std::uint32_t numBufs;
<a name="l00172"></a>00172   
<a name="l00176"></a>00176   <a class="code" href="classbadgerdb_1_1_buf_hash_tbl.html" title="Hash table class to keep track of pages in the buffer pool.">BufHashTbl</a> *hashTable;
<a name="l00177"></a>00177 
<a name="l00181"></a>00181   <a class="code" href="classbadgerdb_1_1_buf_desc.html" title="Class for maintaining information about buffer pool frames.">BufDesc</a> *bufDescTable;
<a name="l00182"></a>00182 
<a name="l00186"></a>00186   <a class="code" href="structbadgerdb_1_1_buf_stats.html" title="Class to maintain statistics of buffer usage.">BufStats</a> bufStats;
<a name="l00187"></a>00187 
<a name="l00191"></a>00191   <span class="keywordtype">void</span> advanceClock();
<a name="l00192"></a>00192 
<a name="l00199"></a>00199   <span class="keywordtype">void</span> allocBuf(<a class="code" href="namespacebadgerdb.html#a1e7378fbefaea050a47e6cde929e9c01" title="Identifier for a frame in buffer pool.">FrameId</a> &amp; frame);
<a name="l00200"></a>00200 
<a name="l00201"></a>00201  <span class="keyword">public</span>:
<a name="l00205"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa498047fc351652d0bc7eabf6cb62ab0">00205</a>   <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>* <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa498047fc351652d0bc7eabf6cb62ab0">bufPool</a>;
<a name="l00206"></a>00206 
<a name="l00210"></a>00210   <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a18b7cf23b619c7c0e593d1dc45da77b4">BufMgr</a>(std::uint32_t bufs);
<a name="l00211"></a>00211   
<a name="l00215"></a>00215   <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aab08001e1be18bfbd4af9113e91cf953">~BufMgr</a>();
<a name="l00216"></a>00216 
<a name="l00226"></a>00226   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a9f853f0f1d4628e7e14374d0c7c6a4f3">readPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> PageNo, <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>*&amp; page);
<a name="l00227"></a>00227 
<a name="l00236"></a>00236   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#aa9bdf04c8543f59744db22efa9420c89">unPinPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> PageNo, <span class="keyword">const</span> <span class="keywordtype">bool</span> dirty);
<a name="l00237"></a>00237 
<a name="l00246"></a>00246   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#ab9ae3b12aac55b119b5763e3de2a4d2b">allocPage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> &amp;PageNo, <a class="code" href="classbadgerdb_1_1_page.html" title="Class which represents a fixed-size database page containing records.">Page</a>*&amp; page); 
<a name="l00247"></a>00247 
<a name="l00257"></a>00257   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#acc61d1985720411ebb76e70f702827d3">flushFile</a>(<span class="keyword">const</span> <a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file);
<a name="l00258"></a>00258 
<a name="l00266"></a>00266   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a870a80a0f0abcf3b640b913b46b64486">disposePage</a>(<a class="code" href="classbadgerdb_1_1_file.html" title="Class which represents a file in the filesystem containing database pages.">File</a>* file, <span class="keyword">const</span> <a class="code" href="namespacebadgerdb.html#a1f49e404293bf4240756b89b53b1587a" title="Identifier for a page in a file.">PageId</a> PageNo);
<a name="l00267"></a>00267 
<a name="l00271"></a>00271   <span class="keywordtype">void</span>  <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a598b3112b8193af603f5bc97c478a671">printSelf</a>();
<a name="l00272"></a>00272 
<a name="l00276"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#a93148e1af99f06f4f264d948920b7c1c">00276</a>   <a class="code" href="structbadgerdb_1_1_buf_stats.html" title="Class to maintain statistics of buffer usage.">BufStats</a> &amp; <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a93148e1af99f06f4f264d948920b7c1c">getBufStats</a>()
<a name="l00277"></a>00277   {
<a name="l00278"></a>00278     <span class="keywordflow">return</span> bufStats;
<a name="l00279"></a>00279   }
<a name="l00280"></a>00280 
<a name="l00284"></a><a class="code" href="classbadgerdb_1_1_buf_mgr.html#a702a264ae946b334414e51700edd81a0">00284</a>   <span class="keywordtype">void</span> <a class="code" href="classbadgerdb_1_1_buf_mgr.html#a702a264ae946b334414e51700edd81a0">clearBufStats</a>() 
<a name="l00285"></a>00285   {
<a name="l00286"></a>00286     bufStats.<a class="code" href="structbadgerdb_1_1_buf_stats.html#a04a848e5458491fd3ea56133464cadbd">clear</a>();
<a name="l00287"></a>00287   }
<a name="l00288"></a>00288 };
<a name="l00289"></a>00289 
<a name="l00290"></a>00290 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Wed Jan 30 2013 14:17:48 for BadgerDB by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
